package com.kucai.yifaqapp.model.network;

import com.google.gson.Gson;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * Created by admin on 2018/12/5.
 */

public class HttpUtils {

    public void performPost(Map<Object, Object> map,String mUrl) {
        Gson mGson=new Gson();
        String params = mGson.toJson(map);
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        RequestBody body = RequestBody.create(JSON, params);

        final Request request = new Request.Builder()
                .url(mUrl)
                .post(body)
                .build();
        OkHttpClient instance = new OkHttpClient().newBuilder()
                .protocols(Collections.singletonList(Protocol.HTTP_1_1))
                .build();
        instance.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, final Response response) throws IOException {

            }
        });
    }
}
